function [] = computeMultiplyingFactors_consumerAdoptions(runId)

%%% Add paths
addpath('../model_funcs');
addpath('../general_funcs');

%%% Get input / output paths
config = getConfig_consumerAdoptions(runId);

outputFolder = createFolderIfNotExist(sprintf('%s/multiplyingFactors', config.runFolder));
outputMatFile = sprintf('%s/multiplyingFactors.mat', outputFolder);
outputCSVFile  = sprintf('%s/multiplyingFactors.csv', outputFolder);
outputCSVFile2  = sprintf('%s/multiplyingFactors2.csv', outputFolder);

%%% Load data
load(sprintf('%s/runData.mat', config.runFolder), 'data');

%%%  Load parameter estimates
load(sprintf('%s/results.mat', config.runFolder), 'params_hat', 'params_ses');
params = params_hat; clear params_hat;

%% Get paramNames and paramVals
paramNames = get_param_names_consumerAdoptions(data);


%%% Rescale parameters that need to be rescaled
idx = find(strcmp(paramNames, 'Beta origdest(Weight_TouristTrip x 1e1) on NewConsumers'));
if ~isempty(idx)
	params(idx) = params(idx)*10;
	params_ses(idx) = params_ses(idx)*10;
	paramNames{idx} = 'Beta origdest(Weight_TouristTrip x 1e1) on NewConsumers';
end

%%% Set DeltaX
NumParams = length(params);
DeltaX = ones(NumParams,1);
DeltaX(strcmp(paramNames, 'Beta origdestMobilitePro on NewConsumers')) = 0.01;
DeltaX(strcmp(paramNames, 'Beta origdest(Weight_TouristTrip x 1e1) on NewConsumers')) = 0.01;

%%% Clean up parameter names + retain only relevant ones
paramNames = strrep(paramNames, 'Beta ', '');
paramNames = strrep(paramNames, ' on NewConsumers', '');
rowNamesMapping = getRowNamesMapping();
[flag,idxes] = ismember(paramNames, rowNamesMapping(:,1));
idxes       = idxes(flag);
params      = params(flag);
params_ses  = params_ses(flag);
DeltaX      = DeltaX(flag);
paramNames = rowNamesMapping(idxes,2);
myVarNames = {'Dummy for same canton'; 'Dummy for contiguous cantons'; 'Dummy for same departement'; ...
	'Commuters from k to kprime (per capita)'; 'Leisure trips from k to kprime (per capita)'; ...
	'February 2013 spike'; 'Summer 2013 (TV ad campaign)'; 'Ad campaign in Parisian transportation at k1'; ...
	'November 2013 (TV ad campaign)'; 'Jan 5th 2014 (TV appearance)'; 'Jan 12th 2014 (TV appearance)'; ...
	'Rail strike day'; 'Week-end day'; 'National holiday'; 'School vacation day at k1'};
[flag2,idxes] = ismember(myVarNames, paramNames); assert(all(flag2));
paramNames = paramNames(idxes);
params     = params(idxes);
params_ses = params_ses(idxes);
DeltaX     = DeltaX(idxes);

%%% Output results
multiplyingFactors_hat = exp(params .* DeltaX);
multiplyingFactors_ses = abs(DeltaX) .* multiplyingFactors_hat .* params_ses;

% Make a table
M1 = table(multiplyingFactors_hat, multiplyingFactors_ses);
M1.Properties.RowNames = paramNames;

NumRows = size(M1,1);
mystrings = cell(NumRows,1);
for ss = 1:NumRows
	mystrings{ss} = sprintf('%.2f (%.2f)', multiplyingFactors_hat(ss), multiplyingFactors_ses(ss));
end
M2 = cell2table(mystrings);
M2.Properties.RowNames = paramNames;
M2.Properties.VariableNames = {'MultiplyingFactor'};

disp(M2);

% Save to output files
save(outputMatFile, 'multiplyingFactors_hat', 'multiplyingFactors_ses', 'M1');
writetable(M1, outputCSVFile, 'WriteRowNames', true);
writetable(M2, outputCSVFile2, 'WriteRowNames', true);

end
